Interactive R in Your Browser with WebR
Run R Code in the Browser - No Installation Required
The WebR Playground allows users to write and execute R code directly in their browser. This feature is ideal for beginners wanting to experiment with R or for quick code testing when away from the main development environment.
What is WebR?
WebR is a version of R compiled to WebAssembly, enabling R code execution directly in web browsers. This provides:
- No installation required
- Instant access to R functionality
- Code execution on any device with a modern browser
Using the WebR Playground
Current Limitations
Please note that this basic implementation has some limitations:
- No plotting capability is available
- Package installation is not supported
- Only basic R functionality is available
For full R functionality, RStudio or other complete R environments are recommended.
Example Code for Practice
The following simple R code examples can be tested in the WebR Playground:
Basic Calculations
# Basic arithmetic
2 + 2 * 5
sqrt(16)
log(10)
# Create and manipulate vectors
<- c(1, 2, 3, 4, 5)
x mean(x)
sd(x)
sum(x)
Data Analysis
# Create some sample data
<- 1:10
x <- c(2, 4, 6, 8, 7, 12, 14, 16, 18, 20)
y
# Print the data
cat("x values:", x, "\n")
cat("y values:", y, "\n")
# Calculate some statistics
<- mean(x)
mean_x <- mean(y)
mean_y cat("Mean of x:", mean_x, "\n")
cat("Mean of y:", mean_y, "\n")
# Fit a linear model
<- lm(y ~ x)
model summary(model)
Working with Built-in Datasets
# Explore the built-in mtcars dataset
data(mtcars)
head(mtcars)
summary(mtcars)
# Basic statistics
cor(mtcars$mpg, mtcars$wt)
t.test(mtcars$mpg[mtcars$am == 0], mtcars$mpg[mtcars$am == 1])
Future Enhancements
- Support for basic plotting
- Access to more packages
- Ability to save and share code snippets